package com.zenchn.schedule.task;

import com.zenchn.enums.CommonStatusEnum;
import com.zenchn.model.TSysAccount;
import com.zenchn.model.TSysAccountExample;
import com.zenchn.service.AccountService;
import com.zenchn.utils.SpringBeanUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 *  账户 过期停用 定时任务
 * @author panbingqi
 * @date 2021-06-01
 */
@Component
public class AccountDisableTask implements Runnable {

    private Logger mLogger = LoggerFactory.getLogger(AccountDisableTask.class);

    @Override
    public void run() {
        try {
            mLogger.debug("账户过期停用任务执行");

            AccountService accountService = SpringBeanUtil.getBean(AccountService.class);

            //查询账户表已过期的账户 置为停用状态
            TSysAccountExample accountExample = new TSysAccountExample();
            accountExample.createCriteria().andExpireTimeLessThan(LocalDateTime.now()).andStatusEqualTo(CommonStatusEnum.ENABLE.getCode());

            TSysAccount updateAcc = new TSysAccount();
            updateAcc.setStatus(CommonStatusEnum.DISABLE.getCode());
            accountService.updateByExampleSelective(updateAcc, accountExample);
        } catch (Exception e) {
            e.printStackTrace();
            mLogger.error("账户过期停用任务执行失败，原因:{}",e.getMessage());
        }
    }
}
